#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Book
{
	char name[20];
	int price;
} book[] = { {"TheNowcoder",100},{"Abook",20},{"BBook",300} };
int com(const void* p1, const void* p2)
{
	return ((struct Book*)p1)->price - ((struct Book*)p2)->price;
}
//int com(const void* p1, const void* p2)
//{
//	return strcmp(((struct Book*)p1)->name, ((struct Book*)p2)->name);
//}
void swap(char* buff1, char* buff2, int size)
{
	for (int i = 0; i < size; i++)
	{
		char tmp = *buff1;
		*buff1 = *buff2;
		*buff2 = tmp;
		buff1++;
		buff2++;
	}
}
void qsort_(void* baes, int num, int size, int(*com)(const void* p1, const void* p2))
{
	int flag = 1;
	int i, j;
	for (i = 0; i < num-1; i++)
	{
		for (j = 0; j < num - 1 - i; j++)
		{
			if (com((char*)baes + j * size , (char*)baes + (j + 1) * size)>0)
			{
				swap((char*)baes + j * size, (char*)baes + (j + 1) * size, size);
				flag = 0;
			}
		}
		if (flag == 1)
			break;
	}
}
int main()
{
	int num = sizeof(book) / sizeof(book[0]);
	int size = sizeof(book[0]);
	qsort_(book, num, size, com);
	/*qsort(book, num,size, compar);*/
	for (int i = 0; i < 3; i++)
	{
		printf("%s %d\n", book[i].name, book[i].price);
	}
	return 0;
}
